package com.ant.collect.service.impl;

import com.ant.collect.dto.SupplysideAccessoriesDto;
import com.ant.collect.mapper.SupplysideAccessoriesMapper;
import com.ant.collect.pojo.SupplysideAccessories;
import com.ant.collect.service.IDictionaryService;
import com.ant.collect.service.ISupplysideAccessoriesService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hzd
 * @since 2025-10-31
 */
@Service
public class SupplysideAccessoriesServiceImpl extends ServiceImpl<SupplysideAccessoriesMapper, SupplysideAccessories> implements ISupplysideAccessoriesService {

    @Autowired
    IDictionaryService dictionaryService;

    @Override
    public void save(SupplysideAccessoriesDto dto) {
//        String accessoryCode = dto.getAccessoryCode();
//        List<Integer> resultList = Arrays.stream(accessoryCode.split(","))
//                .filter(s -> !s.isEmpty()) // 过滤空字符串
//                .map(Integer::parseInt)   // 转换为整数
//                .collect(Collectors.toList());
//        Integer lastItem = 1;
//        if (!resultList.isEmpty()) { // 先判断列表非空
//            lastItem = resultList.get(resultList.size() - 1);
//        }
//        Dictionary val = dictionaryService.getOne(new QueryWrapper<Dictionary>()
//                .eq("id", lastItem)
//                .eq("dic_type",3));
        SupplysideAccessories tal=new SupplysideAccessories();
        tal.setProductId(dto.getProductId());
        tal.setAccessoryName(dto.getAccessoryName());
        tal.setAccessoryCategory(dto.getAccessoryCategory());
        tal.setAccessoryNature(dto.getAccessoryNature());
        tal.setAccessoryKind(dto.getAccessoryKind());
        tal.setAccessoryType(dto.getAccessoryType());
        tal.setAccessoryTypeOne(dto.getAccessoryTypeOne());
        tal.setAccessoryTypeTwo(dto.getAccessoryTypeTwo());
        tal.setManufacturer(dto.getManufacturer());
        tal.setProcessSteps(dto.getProcessSteps());
        tal.setDensity(dto.getDensity());
        tal.setQualityScore(dto.getQualityScore());
        tal.setVocUrl(dto.getVocUrl());
        tal.setVocValues(dto.getVocValues());
        tal.setVocId(dto.getVocId());
        tal.setVocDosage(dto.getVocDosage());
        tal.setCreationTime(LocalDateTime.now());
        if(dto.getId()==null){
            baseMapper.insert(tal);
        }else{
            baseMapper.updateById(tal);
        }

//        Integer isVoc=1;
//        if(dto.getVocValues()> Integer.valueOf(val==null?"0": val.getDicValue())){
//            isVoc=2;
//        }
    }

    @Override
    public List<SupplysideAccessories> listById(Integer id) {
        return baseMapper.selectList(new QueryWrapper<SupplysideAccessories>().eq("product_id",id));
    }
}
